﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/C#" runat="server">

    private void Build(SiteMapNodeCollection childNodes, bool first)
    {
        foreach (SiteMapNode node in childNodes)
        {
            if (node.ChildNodes.Count == 0)
            {
                Response.Write(String.Format(("<li><a href='{0}'>{1}</a></li>"), node.Url, node.Title));
            }
            else
            {
                var clz = first ? "child" : "";
                Response.Write(String.Format(("<li><a href='{0}' class='" + clz + "'>{1}</a>"), node.Url, node.Title));
                Response.Write("<ul>");
                this.Build(node.ChildNodes, false);
                Response.Write("</ul>");

                Response.Write("</li>");
            }
        }
    }

</script>

<ul>
    <%
        if (Request.IsAuthenticated)
        {
    %>
    <li><a>
        <%=Html.Encode(Page.User.Identity.Name)%></a>
        <ul>
            <li>
                <%=Html.ActionLink("注销", "LogOff", "Account", new {@class = "child"})%>
            </li>
            <li>
                <%=Html.ActionLink("更改密码", "ChangePassword", "Account")%>
            </li>
        </ul>
    </li>
    <%
        }
        else
        {
    %>
    <li>
        <%=Html.ActionLink("登录", "LogOn", "Account")%></li>
    <%
        }
    %>
    <%
        Build(SiteMap.RootNode.ChildNodes[1].ChildNodes, true);%>
</ul>
